﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using DevExpress.XtraCharts;
using System.Collections;
using DevExpress.Utils;

namespace Lamex.mCapacity.UI
{
    public partial class frmCAP_Owed_Production_Plan : frmBaseChild
    {
        string strCondition = "";
        string strSql = "";

        public frmCAP_Owed_Production_Plan()
        {
            InitializeComponent();
        }

        private void frmCAP_Capacity_Analysis_Tool_Resize(object sender, EventArgs e)
        {
            panel_R1.Height = (this.Height - panelTop.Height) / 2;
            panel_R2.Height = panel_R1.Height;
        }

        private void frmCAP_Capacity_Analysis_Tool_Load(object sender, EventArgs e)
        {
            setDataForQueryType("SUB_FACTORY");
            comboBox1.Text = "全部";
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            using (WaitDialogForm wdf = new WaitDialogForm("请稍侯", "数据分析中......", new Size(400, 80)))
            {
                strCondition = getQueryCondition();
                strSql = getQuerySqlString(strCondition);

                setAnalizeResultData(strCondition);
                setAnalizeDetailData(strSql);
                setAnalizeChartData(strSql);
            }
        }

        private string getQueryCondition()
        {
            string strType = "";
            string strCondition = "";
            string strSelection = comboBox1.Text.ToString();
            if (radioFactory.Checked == true)
            {
                strType = "分厂";
            }
            else
            {
                strType = "工作站";
            }

            switch (strSelection)
            {
                case "全部":
                    strCondition = "";
                    break;
                default:
                    strCondition = " AND " + strType + @" = '" + strSelection + @"'";
                    break;
            }

            return strCondition;
        }

        private string getQuerySqlString(string strCondition)
        {
            string strSql = "";
            strSql = @"                SELECT 分厂,工作站,c.工序代码,工序名称,欠货工时,排产天数,欠货vs定员,
				A_推荐定员,A_日均排时,A_欠货vs建议,
				B_推荐定员,B_日均排时,B_欠货vs建议,
				C_推荐定员,C_日均排时,C_欠货vs建议
                FROM
                (SELECT 分厂,工作站,工序代码,工序名称,欠货工时,排产天数,欠货vs定员 AS 欠货vs定员,
				推荐定员 AS C_推荐定员,日均排时 AS C_日均排时,欠货vs建议 AS C_欠货vs建议
                FROM View_OP_Capacity_Priority_Overtime) AS d
                LEFT JOIN
                (SELECT a.工序代码,
				a.A_推荐定员,a.A_日均排时,a.A_欠货vs建议,
				B_推荐定员,B_日均排时,B_欠货vs建议
                FROM
                (SELECT 工序代码,
				推荐定员 AS B_推荐定员,日均排时 AS B_日均排时,欠货vs建议 AS B_欠货vs建议
                FROM View_OP_Capacity_Priority_Manpower) AS b
                LEFT JOIN
                (SELECT 工序代码,
				推荐定员 AS A_推荐定员,日均排时 AS A_日均排时,欠货vs建议 AS A_欠货vs建议
                FROM View_OP_Capacity_Priority_Balance) AS a
                ON a.工序代码=b.工序代码) AS c
                ON c.工序代码=d.工序代码
			    WHERE 欠货工时 > 0" + strCondition + @"
                ORDER BY 工序代码";
            return strSql;
        }

        //加载分析结果数据
        private void setAnalizeResultData(string strCondition)
        {
            string sql = "";
            sql = @"            SELECT 'A-综合优化方案' AS 类别,
			    CAST(SUM(A_推荐定员) AS DECIMAL(18,1)) AS 推荐定员,
			    CAST(SUM(A_可用工时) AS DECIMAL(18,1)) AS 可用工时,
			    CAST(SUM(A_加班工时) AS DECIMAL(18,1)) AS 加班工时,
                CAST(SUM((A_可用工时-A_加班工时)+A_加班工时*1.2)*26.8 AS DECIMAL(18,1)) AS 人工成本
                FROM View_OP_Capacity_Optimized_Result
			    WHERE 欠货工时 > 0" + strCondition + @"
			    UNION
			    SELECT  'B-人员调配优先' AS 类别,
			    CAST(SUM(B_推荐定员) AS DECIMAL(18,1)) AS 推荐定员,
			    CAST(SUM(B_可用工时) AS DECIMAL(18,1)) AS 可用工时,
			    CAST(SUM(B_加班工时) AS DECIMAL(18,1)) AS 加班工时,
                CAST(SUM((B_可用工时-B_加班工时)+B_加班工时*1.2)*26.8 AS DECIMAL(18,1)) AS 人工成本
                FROM View_OP_Capacity_Optimized_Result
			    WHERE 欠货工时 > 0" + strCondition + @"
			    UNION
			    SELECT  'C-工时调整优先' AS 类别,
			    CAST(SUM(C_推荐定员) AS DECIMAL(18,1)) AS 推荐定员,
			    CAST(SUM(C_可用工时) AS DECIMAL(18,1)) AS 可用工时,
			    CAST(SUM(C_加班工时) AS DECIMAL(18,1)) AS 加班工时,
                CAST(SUM((C_可用工时-C_加班工时)+C_加班工时*1.2)*26.8 AS DECIMAL(18,1)) AS 人工成本
                FROM View_OP_Capacity_Optimized_Result
			    WHERE 欠货工时 > 0" + strCondition + @"
			    ORDER BY 类别";

            DataTable dt = null;
            dt = Lamex.Base.BaseBuildSql.GetDataTableBySql(sql);
            gridControl1.DataSource = dt;
            gridView1.BestFitColumns();
            gridView2.OptionsBehavior.Editable = false;
            //gridView1.OptionsView.ColumnAutoWidth = false;
        }

        private void setAnalizeDetailData(string strSql)
        {

            #region 欠货产能分析 View_OP_Capacity_Owed_Analize

            //SELECT b.分厂,b.工作站,b.工序代码,b.工序名称,b.计划排时,b.当前定员,b.欠货工时,b.工时系数,a.排产天数, 
            //CASE WHEN b.当前定员*a.排产天数=0 THEN 0 ELSE CAST(b.欠货工时/(b.当前定员*a.排产天数) AS DECIMAL(18,1)) END AS 日均排时, 
            //CASE WHEN b.当前定员*a.排产天数*b.计划排时=0 THEN 0 ELSE CAST(b.欠货工时/(b.当前定员*a.排产天数*b.计划排时) AS DECIMAL(18,2)) END AS 欠货vs定员
            //FROM (SELECT 分厂,工作站,工序代码,LEFT(工序名称,8)+'...' AS 工序名称,计划排时,当前定员,欠货工时,工时系数
            //FROM View_OP_Capacity_Owed_Hours) AS b 
            //LEFT JOIN
            //(SELECT 工序代码,欠货工时,计划排时,当前定员, 
            //CASE WHEN 工时系数>=5 THEN 5 ELSE CEILING(工时系数) END AS 排产天数
            //FROM View_OP_Capacity_Owed_Hours) AS a 
            //ON a.工序代码=b.工序代码

            #endregion

            #region 产能分析及日常安排计划算法：综合平衡法 View_OP_Capacity_Priority_Balance

            //--总原则：
            //--加班控制在11小时之内
            //--排产天数控制在设定周期内，即计划完成天数
            //--逻辑：
            //--根据工时系数求排产天数
            //--根据排产天数求排产系数
            //--根据排产系数确定日均排时
            //--如果排产系数<=0.9，日均排时为8；<=1.1，10；>1.1，12
            //--根据日均排时计算推荐定员
            //--最后计算优化前后排产比例

            //SELECT h.分厂, h.工作站, h.工序代码, h.工序名称, h.欠货工时, h.工时系数, g.排产天数, g.排产系数, h.当前定员, g.推荐定员, h.计划排时, 
            //CAST(g.日均排时 AS DECIMAL(18,1)) AS 日均排时, 
            //CASE WHEN h.当前定员*h.计划排时*g.排产天数=0 THEN 0 ELSE CAST(h.欠货工时/(h.当前定员*h.计划排时*g.排产天数) AS DECIMAL(18,2)) END AS 欠货vs定员,
            //CASE WHEN g.推荐定员*g.日均排时*g.排产天数=0 THEN 0 ELSE CAST(h.欠货工时/(g.推荐定员*g.日均排时*g.排产天数) AS DECIMAL(18,2)) END AS 欠货vs建议  
            //FROM
            //(SELECT 分厂,工作站,工序代码,LEFT(工序名称,8)+ '...' AS 工序名称,计划排时,当前定员, 欠货工时, 工时系数
            //FROM View_OP_Capacity_Owed_Hours) AS h
            //LEFT JOIN
            //(SELECT f.工序代码,e.排产天数,e.排产系数,e.日均排时,
            //CASE WHEN e.日均排时*e.排产天数=0 THEN 0 WHEN e.欠货工时 / (e.日均排时 * e.排产天数) <= 0.5 THEN 0.5 
            //ELSE CAST(ROUND(e.欠货工时/(e.日均排时*e.排产天数),0) AS DECIMAL(18,1)) END AS 推荐定员
            //FROM
            //(SELECT 工序代码
            //FROM View_OP_Capacity_Owed_Hours) AS f
            //LEFT JOIN
            //(SELECT d.工序代码,c.欠货工时,c.排产天数,c.排产系数,
            //CASE WHEN c.排产系数<=0.5 THEN 4 WHEN c.排产系数<=0.9 THEN 8 WHEN c.排产系数<=1.1 THEN 10 WHEN c.排产系数<=99 THEN 11 ELSE NULL END AS 日均排时
            //FROM
            //(SELECT 工序代码
            //FROM View_OP_Capacity_Owed_Hours) AS d
            //LEFT JOIN
            //(SELECT b.工序代码,a.欠货工时,a.排产天数,
            //CASE WHEN a.排产天数=0 THEN 0 ELSE CAST(a.欠货工时/(a.计划排时*a.当前定员*a.排产天数) AS decimal(18,3)) END AS 排产系数
            //FROM
            //(SELECT 工序代码
            //FROM View_OP_Capacity_Owed_Hours) AS b
            //LEFT JOIN
            //(SELECT 工序代码,欠货工时,计划排时,当前定员,
            //CASE WHEN 工时系数>=5 THEN 5 ELSE CEILING(工时系数) END AS 排产天数
            //FROM View_OP_Capacity_Owed_Hours) AS a
            //ON a.工序代码=b.工序代码) AS c
            //ON c.工序代码=d.工序代码) as e
            //ON e.工序代码=f.工序代码) as g
            //ON g.工序代码=h.工序代码

            #endregion

            #region 产能分析及日常安排计划算法：优先调配人员 View_OP_Capacity_Priority_Manpower

            //--总原则：
            //--加班控制在10小时之内
            //--排产天数控制在设定周期内，即计划完成天数
            //--逻辑：
            //--根据工时系数求排产天数
            //--根据排产天数求排产系数
            //--根据排产系数计算推荐定员
            //--最后计算优化前后排产比例

            //SELECT f.分厂, f.工作站, f.工序代码, f.工序名称, f.欠货工时, f.工时系数, e.排产天数, e.排产系数, f.当前定员, e.推荐定员, f.计划排时, 
            //CASE WHEN e.排产天数 = 0 THEN 0 WHEN e.排产系数<=0.5 THEN 4 WHEN e.排产系数<=0.9 THEN 8 ELSE CAST(e.排产天数 / e.排产天数 * f.计划排时 AS DECIMAL(18,1)) END AS 日均排时, 
            //CASE WHEN f.当前定员*f.计划排时*e.排产天数=0 THEN 0 ELSE CAST(f.欠货工时/(f.当前定员*f.计划排时*e.排产天数) AS DECIMAL(18,2)) END AS 欠货vs定员,
            //CASE WHEN e.推荐定员*e.计划排时*e.排产天数=0 THEN 0 ELSE CAST(f.欠货工时/(e.推荐定员*e.计划排时*e.排产天数) AS DECIMAL(18,2)) END AS 欠货vs建议  
            //FROM
            //(SELECT 分厂,工作站,工序代码,LEFT(工序名称,8)+ '...' AS 工序名称,计划排时,当前定员, 欠货工时, 工时系数
            //FROM View_OP_Capacity_Owed_Hours) AS f
            //LEFT JOIN
            //(SELECT d.工序代码,c.欠货工时,c.计划排时,c.排产天数,c.排产系数,
            //--小于0.5, 0.5, 大于0.5四舎五入
            //CASE WHEN c.计划排时*c.排产天数=0 THEN 0 WHEN c.欠货工时/(c.计划排时*c.排产天数)<=0.5 THEN 0.5 
            //ELSE CAST(ROUND(c.欠货工时/(c.计划排时*c.排产天数),0) AS DECIMAL(18,1)) END AS 推荐定员
            //FROM
            //(SELECT 工序代码
            //FROM View_OP_Capacity_Owed_Hours) AS d
            //LEFT JOIN
            //(SELECT b.工序代码,a.欠货工时,a.计划排时,a.排产天数,
            //CASE WHEN a.排产天数=0 THEN 0 ELSE CAST(a.欠货工时/(a.计划排时*a.当前定员*a.排产天数) AS decimal(18,3)) END AS 排产系数
            //FROM
            //(SELECT 工序代码
            //FROM View_OP_Capacity_Owed_Hours) AS b
            //LEFT JOIN
            //(SELECT 工序代码,欠货工时,计划排时,当前定员,
            //CASE WHEN 工时系数>=5 THEN 5 ELSE CEILING(工时系数) END AS 排产天数
            //FROM View_OP_Capacity_Owed_Hours) AS a
            //ON a.工序代码=b.工序代码) AS c
            //ON c.工序代码=d.工序代码) AS e
            //ON e.工序代码=f.工序代码

            #endregion

            #region 产能分析及日常安排计划算法：优先增加工时 View_OP_Capacity_Priority_Overtime

            //--总原则：
            //--加班控制在12小时之内
            //--排产天数控制在设定周期内，即计划完成天数
            //--逻辑：
            //--根据工时系数求排产天数
            //--根据排产天数求排产系数
            //--根据排产系数确定日均排时
            //--如果排产系数<=0.9，日均排时为8；<=1.1，10；>1.1，12
            //--根据日均排时计算推荐定员
            //--最后计算优化前后排产比例

            //SELECT h.分厂, h.工作站, h.工序代码, h.工序名称, h.欠货工时, h.工时系数, g.排产天数, g.排产系数, h.当前定员, g.推荐定员, h.计划排时, 
            //CAST(g.日均排时 AS DECIMAL(18,1)) AS 日均排时, 
            //CASE WHEN h.当前定员*h.计划排时*g.排产天数=0 THEN 0 ELSE CAST(h.欠货工时/(h.当前定员*h.计划排时*g.排产天数) AS DECIMAL(18,2)) END AS 欠货vs定员,
            //CASE WHEN g.推荐定员*g.日均排时*g.排产天数=0 THEN 0 ELSE CAST(h.欠货工时/(g.推荐定员*g.日均排时*g.排产天数) AS DECIMAL(18,2)) END AS 欠货vs建议  
            //FROM
            //(SELECT 分厂,工作站,工序代码,LEFT(工序名称,8)+ '...' AS 工序名称,计划排时,当前定员, 欠货工时, 工时系数
            //FROM View_OP_Capacity_Owed_Hours) AS h
            //LEFT JOIN
            //(SELECT f.工序代码,e.排产天数,e.排产系数,e.日均排时,
            //CASE WHEN e.日均排时*e.排产天数=0 THEN 0 WHEN e.欠货工时/(e.日均排时*e.排产天数)<=0.5 THEN 0.5 
            //ELSE CAST(ROUND(e.欠货工时/(e.日均排时*e.排产天数),0) AS DECIMAL(18,1)) END AS 推荐定员
            //FROM
            //(SELECT 工序代码
            //FROM View_OP_Capacity_Owed_Hours) AS f
            //LEFT JOIN
            //(SELECT d.工序代码,c.欠货工时,c.排产天数,c.排产系数,
            //CASE WHEN c.排产系数<=0.5 THEN 4 WHEN c.排产系数<=0.9 THEN 8 WHEN c.排产系数<=1.1 THEN 10 WHEN c.排产系数<=1.25 THEN 11 WHEN c.排产系数<=99 THEN 12 ELSE NULL END AS 日均排时
            //FROM
            //(SELECT 工序代码
            //FROM View_OP_Capacity_Owed_Hours) AS d
            //LEFT JOIN
            //(SELECT b.工序代码,a.欠货工时,a.排产天数,
            //CASE WHEN a.排产天数=0 THEN 0 ELSE CAST(a.欠货工时/(a.计划排时*a.当前定员*a.排产天数) AS decimal(18,3)) END AS 排产系数
            //FROM
            //(SELECT 工序代码
            //FROM View_OP_Capacity_Owed_Hours) AS b
            //LEFT JOIN
            //(SELECT 工序代码,欠货工时,计划排时,当前定员,
            //CASE WHEN 工时系数>=5 THEN 5 ELSE CEILING(工时系数) END AS 排产天数
            //FROM View_OP_Capacity_Owed_Hours) AS a
            //ON a.工序代码=b.工序代码) AS c
            //ON c.工序代码=d.工序代码) as e
            //ON e.工序代码=f.工序代码) as g
            //ON g.工序代码=h.工序代码

            #endregion

            #region 产能分析及日常安排计划算法：优化结果 View_OP_Capacity_Optimized_Result

            //SELECT tb4.分厂, tb4.工作站, tb4.工序代码, tb4.工序名称, tb4.欠货工时
            //tb3.A_推荐定员, tb3.A_日均排时, tb3.A_可用工时, tb3.A_加班工时, 
            //tb3.C_推荐定员, tb3.C_日均排时, tb3.C_可用工时, tb3.C_加班工时,
            //tb4.B_推荐定员, tb4.B_日均排时, tb4.B_可用工时, tb4.B_加班工时
            //FROM
            //(SELECT 分厂, 工作站, 工序代码, 工序名称, 欠货工时, 推荐定员 AS B_推荐定员, 日均排时 AS B_日均排时, 
            //推荐定员 * 排产天数 * 日均排时 AS B_可用工时, 
            //CASE WHEN 日均排时 > 8 THEN 推荐定员 * 排产天数 * (日均排时 - 8) ELSE 0 END AS B_加班工时
            //FROM View_OP_Capacity_Priority_Manpower AS m) AS tb4
            //LEFT JOIN 
            //(SELECT tb2.工序代码, 
            //tb1.A_推荐定员, tb1.A_日均排时, tb1.A_可用工时, tb1.A_加班工时, 
            //tb2.C_推荐定员, tb2.C_日均排时, tb2.C_可用工时, tb2.C_加班工时 
            //FROM
            //(SELECT 工序代码, 推荐定员 AS C_推荐定员, 日均排时 AS C_日均排时, 
            //推荐定员 * 排产天数 * 日均排时 AS C_可用工时, 
            //CASE WHEN 日均排时 > 8 THEN 推荐定员 * 排产天数 * (日均排时 - 8) ELSE 0 END AS C_加班工时
            //FROM View_OP_Capacity_Priority_Overtime AS m) AS tb2
            //LEFT JOIN
            //(SELECT 工序代码, 推荐定员 AS A_推荐定员, 日均排时 AS A_日均排时, 
            //推荐定员 * 排产天数 * 日均排时 AS A_可用工时, 
            //CASE WHEN 日均排时 > 8 THEN 推荐定员 * 排产天数 * (日均排时 - 8) ELSE 0 END AS A_加班工时
            //FROM View_OP_Capacity_Priority_Balance AS b) AS tb1
            //ON tb1.工序代码 = tb2.工序代码) AS tb3
            //ON tb3.工序代码 = tb4.工序代码

            #endregion

            DataTable dt = null;
            dt = Lamex.Base.BaseBuildSql.GetDataTableBySql(strSql);
            gridControl2.DataSource = dt;
            gridView2.BestFitColumns();
            gridView2.OptionsBehavior.Editable = false;
            gridView2.Columns[0].BestFit();
            gridView2.Columns[1].BestFit();
            gridView2.Columns[3].BestFit();
            //gridView1.OptionsView.ColumnAutoWidth = false;
        }

        private void setAnalizeChartData(string strSql)
        {
            chartControl1.Series.Clear();

            addChartSeries(strSql, "欠货vs定员");
            addChartSeries(strSql, "A_欠货vs建议");
            addChartSeries(strSql, "B_欠货vs建议");
            addChartSeries(strSql, "C_欠货vs建议");
        }

        private void addChartSeries(string strSql,string strSeriesName)
        {
            DataTable dt1 = Lamex.Base.BaseBuildSql.GetDataTableBySql(strSql);
            if (dt1.Rows.Count != 0)
            {
                Series seriesAuto = new Series("", ViewType.Line);

                foreach (DataRow dr in dt1.Rows)
                {
                    SeriesPoint p = new SeriesPoint();

                    //原值显示
                    double[] d = new double[] { double.Parse(Math.Round((decimal.Parse(dr[strSeriesName].ToString())), 2).ToString()) };
                    p.Values = d;
                    p.Argument = dr["工序代码"].ToString();
                    seriesAuto.Points.Add(p);
                }

                chartControl1.Series.Add(seriesAuto);
                chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
                Legend Legends = (Legend)chartControl1.Legend;
                Legends.Visibility = DevExpress.Utils.DefaultBoolean.True;
                Legends.AlignmentVertical = LegendAlignmentVertical.Top;
                Legends.AlignmentHorizontal = LegendAlignmentHorizontal.Left;
                Legends.TextVisible = true;

                //强制显示所有x轴标签
                XYDiagram diagram = ((XYDiagram)chartControl1.Diagram);
                diagram.AxisX.QualitativeScaleOptions.AutoGrid = false;
                diagram.AxisX.Label.ResolveOverlappingOptions.AllowHide = false;

                //设置Series的标签
                seriesAuto.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;//每个点都显示数据
            }
        }

        private void radioFactory_CheckedChanged(object sender, EventArgs e)
        {
            if (radioFactory.Checked==true)
            {
                setDataForQueryType("SUB_FACTORY");
            }
            else
            {
                setDataForQueryType("WORKSTATION");
            }
        }

        private void setDataForQueryType(string strType)
        {
            ArrayList list = new ArrayList();

            string sql = "";
            sql = @"SELECT DISTINCT " + strType + @" FROM View_OP_Resource_Plan";
            DataTable dt = null;
            dt = Lamex.Base.BaseBuildSql.GetDataTableBySql(sql);          
            foreach (DataRow dr in dt.Rows)
            {
                list.Add(dr[0].ToString().Trim());
            }
            list.Add("全部");
            comboBox1.DataSource = list;
            comboBox1.Text = "全部";
        }

        #region 图形右键菜单

        private void 显示所有ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (WaitDialogForm wdf = new WaitDialogForm("请稍侯", "数据分析中......", new Size(400, 80)))
            {
                strCondition = getQueryCondition();
                strSql = getQuerySqlString(strCondition);
                chartControl1.Series.Clear();

                addChartSeries(strSql, "欠货vs定员");
                addChartSeries(strSql, "A_欠货vs建议");
                addChartSeries(strSql, "B_欠货vs建议");
                addChartSeries(strSql, "C_欠货vs建议");
            }
        }

        private void 欠货vs定员ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (WaitDialogForm wdf = new WaitDialogForm("请稍侯", "数据分析中......", new Size(400, 80)))
            {
                strCondition = getQueryCondition();
                strSql = getQuerySqlString(strCondition);
                chartControl1.Series.Clear();
                addChartSeries(strSql, "欠货vs定员");
            }
        }

        private void a欠货vs建议ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (WaitDialogForm wdf = new WaitDialogForm("请稍侯", "数据分析中......", new Size(400, 80)))
            {
                strCondition = getQueryCondition();
                strSql = getQuerySqlString(strCondition);
                chartControl1.Series.Clear();
                addChartSeries(strSql, "A_欠货vs建议");
            }
        }

        private void b欠货vs建议ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (WaitDialogForm wdf = new WaitDialogForm("请稍侯", "数据分析中......", new Size(400, 80)))
            {
                strCondition = getQueryCondition();
                strSql = getQuerySqlString(strCondition);
                chartControl1.Series.Clear();
                addChartSeries(strSql, "B_欠货vs建议");
            }
        }

        private void c欠货vs建议ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (WaitDialogForm wdf = new WaitDialogForm("请稍侯", "数据分析中......", new Size(400, 80)))
            {
                strCondition = getQueryCondition();
                strSql = getQuerySqlString(strCondition);
                chartControl1.Series.Clear();
                addChartSeries(strSql, "C_欠货vs建议");
            }
        }

        #endregion

        private void 隐藏选项区ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panelTop.Height = 0;
            panel_R1.Height = (this.Height - panelTop.Height) / 2;
            panel_R2.Height = panel_R1.Height;
        }

        private void 显示选项区ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panelTop.Height = 60;
            panel_R1.Height = (this.Height - panelTop.Height) / 2;
            panel_R2.Height = panel_R1.Height;
        }

        //gridView仅复制单元格内容，复制选中行焦点单元格的值
        private void gridView2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control & e.KeyCode == Keys.C)
            {
                Clipboard.SetDataObject(gridView2.GetFocusedRowCellValue(gridView2.FocusedColumn));
                e.Handled = true;
            }

            //或设置属性
            //optionBehavior - CopyToClipboardWithColumnHeader = false;
            //optionSelection - MultiSelectMode = CellSelect;
        }
    }
}